package com.frxuexi.mdm_2207.view

import android.util.Log
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.navigation.NavHostController
import com.frxuexi.lib_base.R
import com.frxuexi.mdm_2207.myview.MyProgressView
import com.tencent.mmkv.MMKV
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.util.Timer
import kotlin.concurrent.timerTask

@Composable
fun WelcomePage(navHostController: NavHostController) {
//    var time by remember {
//        mutableStateOf(5)
//    }
//    LaunchedEffect(key1 = "", block = {
//        launch {
//            for (i in 1..4) {
//                delay(1000)
//                time--
//            }
//            //存储当前时间
//            MMKV.defaultMMKV().encode("pre",System.currentTimeMillis())
//            navHostController.navigate("main")
//        }
//    })

    Box {
        Column(
            Modifier
                .fillMaxSize()
                .background(colorResource(id = R.color.background)),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
//        Row(
//            Modifier
//                .padding(20.dp)
//                .size(50.dp)
//                .background(Color.Yellow, CircleShape)
//                .align(Alignment.End),
//            horizontalArrangement = Arrangement.Center,
//            verticalAlignment = Alignment.CenterVertically
//        ) {
//            Text(text = time.toString())
//        }

            Spacer(modifier = Modifier.height(150.dp))
            Image(painter = painterResource(id = R.drawable.img), contentDescription = "")
            Spacer(modifier = Modifier.height(20.dp))
            Text(text = "MDM")
        }
        AndroidView(factory = {
            val myProgressView = MyProgressView(it,navHostController)
            myProgressView.start()
            myProgressView
        })
    }

}